/**
 * @author Just、倾城
 * @created 2025-11-04
 * @description
 *
 */
public class TimeBasedStrategyFactory {
    public static PricingStrategy getStrategy(String time, String taxiType) {
        // 解析输入时间
        if (time == null || time.trim().isEmpty()) {
            throw new IllegalArgumentException("时间不能为空");
        }

        // 假设格式为 "HH:mm"
        String[] parts = time.split(":");
        if (parts.length != 2) {
            throw new IllegalArgumentException("时间格式不正确，应为 HH:mm 格式");
        }

        int hour = Integer.parseInt(parts[0]);
        int minute = Integer.parseInt(parts[1]);

        // 验证时间合理性
        if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
            throw new IllegalArgumentException("时间值必须在有效范围内");
        }

        // 确定时间段
        int totalMinutes = hour * 60 + minute;

        if (totalMinutes >= 6*60 && totalMinutes < 12*60) {
            return taxiType.equals("A") ? new TaxiA(8.0) : new TaxiB(6.0);
        } else if (totalMinutes >= 12*60 && totalMinutes < 18*60) {
            return taxiType.equals("A") ? new TaxiA(5.0) : new TaxiB(4.0);
        } else if (totalMinutes >= 18*60 && totalMinutes < 24*60) {
            return taxiType.equals("A") ? new TaxiA(3.0) : new TaxiB(2.0);
        } else {
            throw new IllegalArgumentException("无效的时间范围");
        }
    }


}
